/**
 * 
 */
package view;

import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import net.miginfocom.swing.MigLayout;

/**
 * @author Farzana Alam (farzana22@gmail.com)
 * @since May 2013
 *
 */
public class EmailEditorPanel extends JPanel {
	
	// Panel elements
	private JPanel detailsPanel, bodyPanel, buttonPanel;
	
	// Text Fields
	private JTextField _fromAddress, _toAddress, _subjectField;	

	// Email Body TextPane
	private JTextPane _body;
	private JScrollPane _bodySP; 
	
	// Text Labels
	private JLabel fromLabel, toLabel, subjectLabel;
	
	// Panel Buttons
	private JButton sendButton, saveButton;

	/**
	 * 
	 * @param layout
	 */	
	public EmailEditorPanel(MigLayout layout) {
		super(layout);
		
		this.setTextLabels();
		this.setTextFields();
		this.setButoons();
		
		this.setEmailDetailsPanel();
		this.add(detailsPanel, "grow, wrap");
		this.add(bodyPanel, "grow, wrap");
		this.add(buttonPanel, "grow");
	}	
	
	private void setTextLabels() {
		/*
		 * Setting up Text Labels
		 */
		
		fromLabel = new JLabel("From:");
		toLabel = new JLabel("To:");
		subjectLabel = new JLabel("Subject:");
	}	

	private void setTextFields() {
		/*
		 * Initializing Text Fields
		 */
		
		// From Text Field
		_fromAddress = new JTextField();
		_fromAddress.setEditable(false);
		
		// To Text Field
		_toAddress = new JTextField();
		
		// Subject Text Field
		_subjectField = new JTextField();
		
		// Body Text Field
		_body = new JTextPane();
		_bodySP = new JScrollPane(_body);
	}

	private void setButoons() {
		/*
		 * Setting up the buttons;
		 */
		
		// Send Button
		sendButton = new JButton("Send");
		sendButton.setMnemonic(KeyEvent.VK_S);		
		
		// Save Button
		saveButton = new JButton("Save");
		saveButton.setMnemonic(KeyEvent.VK_V);		
	}
	
	private void setEmailDetailsPanel() {
		/*
		 * Setting up the ComposeMailView Email Panels 
		 */
		
		// Email Details Panels
		detailsPanel = new JPanel(new MigLayout("fillx"));
		detailsPanel.add(fromLabel);
		detailsPanel.add(_fromAddress, "growx, wrap");
		detailsPanel.add(toLabel);
		detailsPanel.add(_toAddress, "growx, wrap");	
		detailsPanel.add(subjectLabel);
		detailsPanel.add(_subjectField, "growx, wrap");
		
		// Body Panel
		bodyPanel = new JPanel(new MigLayout("fillx"));		
		bodyPanel.add(_bodySP, "growx, h 100:400:");
		
		// Buttons Panel
		buttonPanel = new JPanel(new MigLayout("fillx"));
		buttonPanel.add(sendButton, "push, al right");
		buttonPanel.add(saveButton, "al right");
	}
	

	// getter for _toAddress
	public JTextField get_toAddress() {
		return _toAddress;
	}

	// getter for _subjectField
	public JTextField get_subjectField() {
		return _subjectField;
	}

	// getter for _body
	public JTextPane get_body() {
		return _body;
	}

	// getter for _fromAddress
	public JTextField get_fromAddress() {
		return _fromAddress;
	}
	
	// getter for SendButton
	public JButton getSendButton() {
		return sendButton;
	}

	// getter for SaveButton
	public JButton getSaveButton() {
		return saveButton;
	}

}
